package com.weiyuwqj.controller.user;

import com.weiyuwqj.api.constant.Message;
import com.weiyuwqj.api.model.BasUserInfo;
import com.weiyuwqj.api.model.BasUserSecurity;
import com.weiyuwqj.api.service.BasUserInfoService;
import com.weiyuwqj.api.service.BasUserSecurityService;
import com.weiyuwqj.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2017/6/29.
 */
@Controller
@RequestMapping("/user/info")
public class UserInfoController{

    @Autowired
    BasUserInfoService userInfoService;
    @Autowired
    BasUserSecurityService userSecurityService;

    /**
     * 根据用户id查询用户信息
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getInfo",method = RequestMethod.POST)
    public Object getInfo(HttpServletRequest request){
        Integer userId=(Integer)request.getSession().getAttribute("userId");//用户id
        return userInfoService.getOneByUserId(userId);
    }

    /**
     * 修改用户信息
     * @param userInfo
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/modifyInfo",method = RequestMethod.POST)
    public Object modifyInfo(BasUserInfo userInfo){
        userInfoService.updateNotNull(userInfo);
        return Message.OK;
    }
    /**
     * 用户基本信息页面跳转
     */
    @RequestMapping(value = "/information")
    public Object modifyInfo(HttpServletRequest request) {
        Integer userId=(Integer)request.getSession().getAttribute("userId");//用户id
        BasUserSecurity security = userSecurityService.getOneByUserId(userId);
        if(security.getRealnameStatus()==1){
            security.setIdentifyCard(StringUtils.getString(security.getIdentifyCard()));
            security.setRealname(StringUtils.getString(security.getRealname()));
            security.setPaymentPassword("");
        }
        request.getSession().setAttribute("security",security);
        return "/main/user/information";
    }

    //查询是否签署自动投标合同
    @ResponseBody
    @RequestMapping(value="/isSignContract")
    public Object isSignContract(HttpServletRequest request){
        Integer userId = (Integer) request.getSession().getAttribute("userId");
       // Map map=userInfoService.isSignContract(userId);
        return null;
    }
}
